home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tpb4_src.zip / MSGMISC.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-13  |  15KB  |  465 lines

  1. { TPBoard 4.2 Copyright (c) 1987,88 by Jon Schneider & Rick Petersen  
  2.   Portions Copyright (c) 1986,87 by Steve Fox and Les Archambault  
  3.   
  4.   Last modified  ::  9-11-88 12:18 pm 
  5. }
  6.  
  7. {$R-}                             {Range checking off}
  8. {$B-}                             {Boolean complete evaluation off}
  9. {$S-}                             {Stack checking off}
  10. {$I+}                             {I/O checking on}
  11. {$N-}                             {No numeric coprocessor}
  12.  
  13. Unit MsgMisc;
  14.  
  15. Interface
  16.  
  17. Uses
  18.   TPCrt, Globals, Core1, NetMisc,
  19.   TPSTRING, TPDOS, Core2, MsgDir;
  20.   
  21.   
  22. procedure mesg_build_index(mesg_area : Byte);
  23.  
  24. procedure Articles;
  25.  
  26. procedure list_file(fname : DosFileName; Dirspec : StrPr);
  27.  
  28. procedure mesg_area_change(req : DosFileName);
  29.  
  30. procedure mesg_delete;
  31.  
  32.  
  33.   {==========================================================================}
  34.   
  35.   
  36. Implementation
  37.  
  38.  
  39. { Scan summary file and build message index list.  Messages are tied to the
  40.   current message area. All messages are accessible in mesg_area #0 (SYSTEM).}
  41.   
  42.   procedure mesg_build_index(mesg_area : Byte);
  43.   
  44.   var
  45.     This            : MesgPtr;
  46.     
  47.   begin
  48.     while MesgBase <> nil do      { Delete old messages }
  49.       begin
  50.         This := MesgBase;
  51.         MesgBase := MesgBase^.next; { Go to next on list }
  52.         Dispose(This)             { Reclaim space }
  53.       end;
  54.     msg_all := 0;
  55.     msg_ind := 0;
  56.     msg_aut := 0;
  57.     msg_sys := 0;
  58.     msg_hi := 0;
  59.     msg_lo := 30000;
  60.     Seek(summ_file, 1);
  61.     while not EoF(summ_file) do
  62.       with summ_rec do
  63.         begin
  64.           Read(summ_file, summ_rec);
  65.           if ((status <> deleted) and (status <> restricted) and (Area = mesg_area)) or (
  66.             mesg_area = 0) then
  67.             begin
  68.               if msg_lo > num then
  69.                 msg_lo := num;
  70.               if num > msg_hi then
  71.                 msg_hi := num;
  72.             end;
  73.           if (status = public) and ((Area = mesg_area) or (mesg_area = 0)) {Public message}
  74.           then
  75.             if (user_loc = user_to) or ((user_to = 0) and
  76.               (num > user_rec.lasthi) and (user_from = 1)) then
  77.               begin
  78.                 Inc(msg_ind);
  79.                 Inc(msg_all);     {add to public count too}
  80.                 mesg_insert(1);
  81.               end
  82.             else if user_loc = user_from then
  83.               begin
  84.                 Inc(msg_aut);
  85.                 Inc(msg_all);
  86.                 mesg_insert(2);
  87.               end
  88.             else
  89.               begin
  90.                 Inc(msg_all);
  91.                 mesg_insert(0)
  92.               end
  93.           else if (status <> deleted) and (user_loc = user_to) and ((Area = mesg_area) or (
  94.             mesg_area = 0)) then
  95.             begin                 { Private message }
  96.               Inc(msg_ind);
  97.               mesg_insert(1)
  98.             end
  99.           else if (status <> deleted) and (user_loc = user_from) and ((Area = mesg_area) or (
  100.             mesg_area = 0)) then
  101.             begin                 { Author of message }
  102.               Inc(msg_aut);
  103.               mesg_insert(2)
  104.             end
  105.           else if mesg_area = 0 then
  106.             begin                 { Sysop can view all messages }
  107.               Inc(msg_sys);
  108.               mesg_insert(3)
  109.             end
  110.         end;
  111.     if msg_lo >= 29999 then
  112.       msg_lo := 0;
  113.     summ_rec.user_from := 0
  114.   end;
  115.   
  116.   
  117.   procedure list_file(fname           : DosFileName;
  118.                       Dirspec         : StrPr);
  119.                       
  120.   var
  121.     work            : StrStd;
  122.     Tfile           : Text;
  123.     ln_count        : Integer;
  124.     OK              : Boolean;
  125.     
  126.   begin
  127.     abort := False;
  128.     SetSect(Dirspec);
  129.     Assign(Tfile, fname);
  130.     {$I-}
  131.     Reset(Tfile); {$I+}
  132.     if IoResult = 0 then
  133.       begin
  134.         ln_count := 1;
  135.         while (not EoF(Tfile)) and (Online) and (not brk) do
  136.           begin
  137.             ReadLn(Tfile, work);
  138.             WriteLn(Com, work);
  139.             if (user_rec.lines <> 99) and (not nonstop) then
  140.               begin
  141.                 Inc(ln_count);
  142.                 if ln_count mod user_rec.lines = 0 then
  143.                   pause;
  144.               end;
  145.           end;
  146.       end
  147.     else
  148.       WriteLn(Com, 'File not available.');
  149.     {$I-}
  150.     Close(Tfile);
  151.     {$I+}
  152.     OK := (IoResult = 0);
  153.     SetSect(HomName);
  154.   end;
  155.   
  156.   
  157.   procedure Articles;
  158.   
  159.   var
  160.     This            : ArtPtr;
  161.     num             : Integer;
  162.     Dirspec         : StrPr;
  163.     
  164.   begin
  165.     if Artbase <> nil then
  166.       begin
  167.         repeat
  168.           This := Artbase;
  169.           WriteLn(Com);
  170.           WriteLn(Com, 'ARTICLES AVAILABLE FOR VIEWING');
  171.           WriteLn(Com);
  172.           while This <> nil do
  173.             begin
  174.               if user_rec.access >= This^.ArtAccs then
  175.                 WriteLn(Com, This^.Artnum, '  ', This^.ArtDesc);
  176.               This := This^.next;
  177.             end;
  178.           WriteLn(Com);
  179.           num := strint(prompt('Number of Article to read [CR to exit]', 3, 'E'));
  180.           This := Artbase;
  181.           while (This <> nil) and (This^.Artnum <> num) do
  182.             This := This^.next;
  183.           if (This^.Artnum = num) and (user_rec.access >= This^.ArtAccs) then
  184.             begin
  185.               Dirspec := This^.Artdrive+':\';
  186.               if (Length(HomName) > 3) and (Dirspec = HomDrv) then
  187.                 begin
  188.                   Dirspec := Dirspec+Copy(HomName, 4, Length(HomName));
  189.                   Dirspec := Dirspec+'\';
  190.                 end;
  191.               Dirspec := Dirspec+'ARTICLES';
  192.               list_file(This^.ArtName, Dirspec);
  193.               pause;
  194.             end;
  195.         until (not Online) or (num = 0);
  196.       end
  197.     else
  198.       begin
  199.         WriteLn(Com);
  200.         WriteLn(Com, ' Articles are not available at this time.');
  201.         WriteLn(Com);
  202.       end;
  203.   end;
  204.   
  205.   
  206.   procedure mesg_area_change(req : DosFileName);
  207.     { Change message area }
  208.     
  209.   const
  210.     col_width       = 16;
  211.     
  212.   var
  213.     col_count,
  214.     col_limit,
  215.     conf_num,
  216.     line_count,
  217.     area_count, i   : Integer;
  218.     This            : AreaPtr;
  219.     pr, echo_rec    : StrPr;
  220.     temp            : Str14;
  221.     SameArea,
  222.     found, OK       : Boolean;
  223.     
  224.     
  225.     procedure display_short;
  226.     
  227.     var
  228.       pad_count       : Byte;
  229.       wrap_on_next    : Boolean;
  230.       
  231.     begin
  232.       WriteLn(Com);
  233.       abort := False;
  234.       col_count := 0;
  235.       This := AreaBase;
  236.       Write(Com, hi, yellow);
  237.       area_count := 1;
  238.       while (not brk) and (This <> nil) do
  239.         begin
  240.           conf_num := This^.AreaConf and 7;
  241.           if (user_rec.access >= This^.AreaAccs) or (test_bit(user_rec.
  242.             conf_flags, conf_num)) then
  243.             begin
  244.               Inc(col_count);
  245.               wrap_on_next := (0 = col_count mod col_limit);
  246.               if wrap_on_next then
  247.                 pad_count := 1
  248.               else
  249.                 pad_count := 13;
  250.               temp := This^.AreaName;
  251.               if temp[1] = '-' then Delete(temp, 1, 1);
  252.               Write(Com, yellow, intstr(area_count, 2), cyan, ' ',
  253.                 pad(temp, pad_count));
  254.               if wrap_on_next then
  255.                 WriteLn(Com);
  256.               Inc(area_count)
  257.             end;
  258.           This := This^.next;
  259.         end;
  260.       Write(Com, cyan);
  261.       if 0 <> col_count mod col_limit then
  262.         WriteLn(Com);
  263.       WriteLn(Com);
  264.     end;
  265.     
  266.     
  267.     procedure display_long;
  268.     
  269.     begin
  270.       WriteLn(Com);
  271.       line_count := 2;
  272.       This := AreaBase;
  273.       area_count := 1;
  274.       while (not brk) and (This <> nil) do
  275.         begin
  276.           conf_num := This^.AreaConf and 7;
  277.           if (user_rec.access >= This^.AreaAccs) or (test_bit(user_rec.conf_flags,
  278.             conf_num)) then
  279.             begin
  280.               temp := This^.AreaName;
  281.               if temp[1] = '-' then Delete(temp, 1, 1);
  282.               temp := intstr(area_count, 2)+' '+temp;
  283.               WriteLn(Com, hi, yellow, pad(temp, 13), low, green, This^.AreaDesc);
  284.               Inc(area_count);
  285.             end;
  286.           This := This^.next;
  287.           if user_rec.lines <> 99 then
  288.             begin
  289.               Inc(line_count);
  290.               if line_count mod user_rec.lines = 0 then
  291.                 pause;
  292.             end;
  293.         end;
  294.       Write(Com, hi, cyan);
  295.       WriteLn(Com);
  296.     end;
  297.     
  298.     
  299.   begin                           {mesg_area_change}
  300.     SameArea := False;
  301.     col_limit := max(1, user_rec.columns div col_width);
  302.     pr := white+'Enter Area Name or #'+cyan;
  303.     if req = '' then
  304.       begin
  305.         WriteLn(Com);
  306.         req := prompt(pr, 12, 'ES?M');
  307.       end;
  308.     if req = ' ' then
  309.       begin
  310.         req := AreaReq;
  311.         SameArea := True;
  312.       end;
  313.     while (req <> '') and (Online) and (not SameArea) do
  314.       begin
  315.         This := AreaBase;
  316.         if (req = '?') or (req = '/') then
  317.           begin
  318.             WriteLn(Com);
  319.             WriteLn(Com, 'Available message areas:');
  320.             display_short;
  321.             repeat
  322.               req := prompt(pr+' ["?" for Descriptions]', 12, 'ES?');
  323.               if (req = '?') or (req = '/') then
  324.                 display_long;
  325.             until (req <> '?') and (req <> '/');
  326.             if req = ' ' then
  327.               begin
  328.                 req := AreaReq;   {default to current}
  329.                 SameArea := True;
  330.               end;
  331.           end
  332.         else if req <> '' then
  333.           begin
  334.             area_count := 1;
  335.             repeat
  336.               conf_num := This^.AreaConf and 7;
  337.               found := (This^.AreaName = req) or (strint(req) = area_count);
  338.               if (not((user_rec.access >= This^.AreaAccs) or
  339.                 (test_bit(user_rec.conf_flags, conf_num)))) then
  340.                 begin
  341.                   Dec(area_count);
  342.                   found := False
  343.                 end;
  344.               if (not found) and (This^.AreaName[1] = '-') then
  345.                 begin
  346.                   temp := This^.AreaName;
  347.                   Delete(temp, 1, 1);
  348.                   found := (temp = req)
  349.                 end;
  350.               if (not found) and (This <> nil) then
  351.                 begin
  352.                   This := This^.next;
  353.                   Inc(area_count)
  354.                 end;
  355.             until found or (This = nil);
  356.             if found and ((user_rec.access >= This^.AreaAccs) or (test_bit(
  357.               user_rec.conf_flags,
  358.               conf_num))) then
  359.               begin
  360.                 if (not SameArea) then
  361.                   begin
  362.                     AreaSet := This^.Area;
  363.                     AreaReq := This^.AreaName;
  364.                     req := '';
  365.                     if (AreaReq <> 'NETMAIL') and
  366.                     (AreaReq[1] <> '-') then
  367.                       begin
  368.                         mesg_build_index(AreaSet);
  369.                         mesg_directory;
  370.                       end
  371.                     else
  372.                       begin
  373.                         found := False;
  374.                         i := 0;
  375.                         Assign(echo_file, echo_name+ext);
  376.                         {$I-}
  377.                         Reset(echo_file) {$I+} ;
  378.                         OK := (IoResult = 0);
  379.                         if OK then
  380.                           begin
  381.                             while ((not EoF(echo_file)) and (not found)) do
  382.                               begin
  383.                                 ReadLn(echo_file, echo_rec);
  384.                                 if Pos(AreaReq, echo_rec) <> 0 then
  385.                                   begin
  386.                                     msg_offset := i;
  387.                                     found := True
  388.                                   end
  389.                                 else
  390.                                   Inc(i);
  391.                               end;
  392.                             if (not found) then
  393.                               begin
  394.                                 msg_offset := 0;
  395.                                 WriteLn(Com,
  396.                                   'Message counters are not maintained for this Area.');
  397.                               end;
  398.                             if msg_offset > 63 then msg_offset := 0;
  399.                             mesg_directory;
  400.                             Close(echo_file)
  401.                           end
  402.                         else
  403.                           begin
  404.                             WriteLn(Com, echo_name, ext, ' not found.');
  405.                             WriteLn(Com, 'Please let the SysOp know.');
  406.                             msg_offset := 0
  407.                           end;
  408.                       end;
  409.                   end;
  410.               end
  411.             else
  412.               begin
  413.                 WriteLn(Com, '"', req, '" not found.  Available message areas:');
  414.                 display_short;
  415.                 repeat
  416.                   req := prompt(pr+' ["?" for Descriptions]', 12, 'ES?');
  417.                   if (req = '?') or (req = '/') then
  418.                     display_long;
  419.                 until (req <> '?') and (req <> '/');
  420.                 if req = ' ' then
  421.                   begin
  422.                     req := AreaReq; {default to current}
  423.                     SameArea := True;
  424.                   end;
  425.               end
  426.           end
  427.       end
  428.   end;
  429.   
  430.   
  431.   procedure mesg_delete;
  432.     { Delete the current message }
  433.     
  434.   var
  435.     This            : MesgPtr;
  436.     
  437.   begin
  438.     summ_rec.status := deleted;
  439.     Seek(summ_file, Pred(FilePos(summ_file)));
  440.     Write(summ_file, summ_rec);
  441.     This := MesgCurr;
  442.     if MesgCurr = MesgBase then
  443.       begin
  444.         MesgCurr := MesgBase^.next;
  445.         MesgBase := MesgBase^.next;
  446.         Dispose(This)
  447.       end
  448.     else if MesgCurr <> nil then
  449.       begin
  450.         MesgCurr := MesgBase;     { Find previous record }
  451.         while MesgCurr^.next <> This do
  452.           MesgCurr := MesgCurr^.next;
  453.         MesgCurr^.next := This^.next; { Make it point to next record }
  454.         if MesgLast = This then
  455.           MesgLast := MesgCurr;
  456.         MesgCurr := MesgCurr^.next;
  457.         Dispose(This)
  458.       end;
  459.     WriteLn(Com, 'Message #', summ_rec.num, ' deleted.')
  460.   end;                            {mesg_delete}
  461.   
  462.   
  463. end.                              { of MSGMISC.PAS}
  464. 
  465.